﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class SiteNavigation_Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            string strPage = Request["page"];
            int page = 1;
            try
            {
                page = int.Parse(strPage);
                if (page < 1)
                {
                    page = 1;
                }
            }
            catch (Exception ex)
            {
                page = 1;
            }
            bd(page);
            CMSModel.CMSEntities dal = DAL.DBManager.GetCmsEmtity();
        }
    }

    public int GetPage()
    {
        return AspNetPager1.CurrentPageIndex;
    }

    void bd(int page)
    {
        CMSModel.CMSEntities dal = DAL.DBManager.GetCmsEmtity();
        #region LK
        var c = dal.SiteType.AsQueryable();
        var name = Server.UrlDecode(Request["name"]);
        if (!string.IsNullOrEmpty(name))
        {
            c = c.Where(x => x.name.Contains(name));
        }
        var id =Server.UrlDecode(Request["id"]);
        //if (!string.IsNullOrEmpty(id))
        //{
        //    c = c.Where(x => x.stid.Contains(id));
        //}
        if (!string.IsNullOrEmpty(id))
        {
            try
            {
                int stid = int.Parse(id);
                c = c.Where(x => x.stid == stid);
            }
            catch 
            {
                return;
            }
        }
        AspNetPager1.RecordCount = c.Count();
        AspNetPager1.CurrentPageIndex = page;
        c = c.OrderBy(x => "id pid").Skip((page - 1) * AspNetPager1.PageSize).Take(AspNetPager1.PageSize);

        Repeater1.DataSource = c;
        Repeater1.DataBind();
        #endregion

        #region

        //var c = dal.NewsType.AsQueryable();
        //var name = Server.UrlDecode(Request["name"]);
        //if (!string.IsNullOrEmpty(name))
        //{
        //    c = c.Where(x => x.name.Contains(name));
        //}
        //var id = Server.UrlDecode(Request["id"]);
        //if (!string.IsNullOrEmpty(id))
        //{
        //    c = c.Where(x => x.id.Contains(id));
        //}
        //AspNetPager1.RecordCount = c.Count();
        //AspNetPager1.CurrentPageIndex = page;
        //c = c.OrderBy(x => "id pid").Skip((page - 1) * AspNetPager1.PageSize).Take(AspNetPager1.PageSize);

        //Repeater1.DataSource = c;
        //Repeater1.DataBind();

        #endregion
    }
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        bd(AspNetPager1.CurrentPageIndex);
    }
}